import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:miaowu/app/module/world/world_content_publish/picker_image_drag_widget.dart';
import 'package:miaowu/app/theme/font.dart';

import 'pond_publish_image_logic.dart';
import 'pond_publish_image_state.dart';

/// @description:
/// @author
/// @date: 2024-09-23 16:13:32
class PondPublishImagePage extends StatefulWidget {
  const PondPublishImagePage({Key? key}) : super(key: key);

  @override
  State<PondPublishImagePage> createState() => _PondPublishImagePageState();
}

class _PondPublishImagePageState extends State<PondPublishImagePage> {
  final PondPublishImageLogic logic = Get.put(PondPublishImageLogic());

  final PondPublishImageState state = Get.find<PondPublishImageLogic>().state;

  // @override
  // void dispose() {
  //   Get.delete<PondPublishImageLogic>();
  //   super.dispose();
  // }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: GetBuilder<PondPublishImageLogic>(
          init: PondPublishImageLogic(),
          initState: (_) {},
          builder: (context) {
            return Container(
              color: const Color(0xFFF5FAF9),
              child: SingleChildScrollView(
                child: buildContentImageWerppar(),
              ),
            );
          }),
      bottomNavigationBar: Container(
        width: double.infinity,
        height: 120,
        padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
        margin: EdgeInsets.only(
            top: 30,
            bottom: MediaQuery.of(context).padding.bottom == 0 ? 10 : MediaQuery.of(context).padding.bottom - 10),
        child: Column(
          children: [
            Container(
              height: 25,
              margin: const EdgeInsets.only(right: 10, bottom: 20),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Image.asset('assets/app/images/auth/auth_check_n.png', width: 15.w),
                  const SizedBox(width: 3),
                  Text('同步到视界', style: TextStyle(color: Colors.black, fontSize: 13.sp))
                ],
              ),
            ),
            GestureDetector(
              onTap: () {
                logic.doPostFeekBack();
                // SnackBaUtils.show();
              },
              child: Container(
                height: 42.h,
                alignment: Alignment.center,
                padding: const EdgeInsets.symmetric(horizontal: 15),
                margin: const EdgeInsets.symmetric(horizontal: 5),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(21.r)), color: const Color(0xFF25D4D0)),
                child: Text('发布',
                    style: TextStyle(color: Colors.white, fontSize: 15.sp, fontWeight: AppFontWeight.medium)),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Container buildContentImageWerppar() {
    return Container(
      padding: const EdgeInsets.only(left: 14, right: 14, bottom: 10, top: 10),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.only(left: 15.w, right: 15.w, bottom: 10),
            decoration:
                BoxDecoration(color: const Color(0xFFF6F6F6), borderRadius: BorderRadius.all(Radius.circular(8.r))),
            child: TextField(
              maxLength: 100,
              focusNode: state.focusNode,
              textInputAction: TextInputAction.done,
              style: TextStyle(color: const Color(0xFF263B38), fontSize: 13.sp, height: 1.5),
              maxLines: 6,
              // controller: _publishState.textController,
              decoration: InputDecoration(
                hintText: '与有趣的Ta相遇吧~',
                hintStyle:
                    TextStyle(color: const Color(0xFF999999), fontSize: 13.sp, fontWeight: AppFontWeight.regular),
                hintMaxLines: 3,
                border: InputBorder.none,
                // counterText: '${_publishState.textController.text.length} / 500'
                // isCollapsed: true,
              ),
              // cursorColor: normalBlackColor,
              onChanged: (value) {
                debugPrint('onChanged--');
                if (value.characters.length >= state.minInputCount) {
                  state.isCanPublish = true;
                } else {
                  state.isCanPublish = false;
                }
                logic.update();
                state.content = value;
                // setState(() {});
                // _publishState.textController.text;
              },
              onEditingComplete: () {
                state.focusNode.unfocus();
              },
            ),
          ),
          // const SizedBox(height: 10),
          PickerImageDragWidget(
            maxAssets: 9,
            callBack: (assetEntityList) async {
              List<String> filePaths = [];
              for (var assetEntity in assetEntityList) {
                File? file = await assetEntity.originFile;
                filePaths.add(file!.path);
              }
              state.filePaths = filePaths;
            },
          ),
        ],
      ),
    );
  }
}
